<template>
  <div>
    <h3>和为{{this.$store.state.sum}}</h3>
    <h1>人员列表</h1>
    <input type="text" placeholder="请输入名字" v-model="name">
    <button @click="add">添加</button>
    <ul>
      <li v-for="item in PersonList" :key="item.id">{{ item.id }}---{{ item.name }}</li>
    </ul>
  </div>
</template>

<script>
import  {nanoid} from "nanoid";

export default {
  name: "Person",
  computed: {
    PersonList() {
      return this.$store.state.PersonList
    }
  }, data() {
    return {
      name: ""
    }
  },
  methods:{
    add(){
      const  personObj={id:nanoid(),name:this.name}
      console.log(personObj)
      this.name=""
      //this.PersonList.push(personObj)
      this.$store.commit("ADDPersonList",personObj)
    }
  }

}
</script>

<style scoped>

</style>